<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model="filterForm.keyword" clearable placeholder="银行卡ID/开户人/责任人" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="开户行" prop="bankID">
          <el-input v-model="filterForm.bankID" clearable placeholder="银行卡ID/开户人/责任人" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="开卡时间" prop="tradeTime">
          <el-date-picker 
          clearable
            v-model="filterForm.tradeTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
          <el-button type="primary" icon="el-icon-refresh" size="mini" @click="handleRefreshButton()">
            刷新
          </el-button>
          <el-button type="primary" size="mini" @click="handleCreate()">
            新建
          </el-button>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column label="卡号" prop="id" sortable="custom" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.bankcardCode }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开户行" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.bankData.bankName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开户人" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.fullname }}</span>
          <span>{{ row.openDate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="责任人" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.subject }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)">
            编辑
          </el-button>
          <el-button type="primary" size="mini" @click="handleRomve(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.start" :limit.sync="filterForm.perpage" @pagination="getList" />

  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/bankcard'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getHost} from '@/utils/socket' // secondary package based on el-pagination
import {getList,BankcardSave} from '@/api/finance/bankcard'

export default {
  name: 'bankcardAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      socket:"",
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
      connected:"loading",
      filterForm: {
        start: 1,
        perpage: 10,
        title: undefined,
        sort: '+id'
      }
    }
  },
  created() {
    this.getList()
  },
  destroyed(){
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log(_this.filterForm)
      getList(_this.filterForm).then((response) => {
        console.log(response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleRefreshButton:function(){
      this.getList()
    },
    handleShow:function(item){
      this.$router.push({ path: 'bankcard-detail', query: { 'bankcardID': item.ID }})
    },
    handleCreate:function(){
      this.$router.push({ path: 'bankcard-add'})
    },
    handleUpdate:function(item){
      this.$router.push({ path: 'bankcard-add', query: { 'bankcardID': item.ID }})
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    },
    handleDelete(row, index) {
      removeFaultinessByID(row.ID).then((response) => {
          if (response.status === 200) {
            this.$message({
              message: '操作Success',
              type: 'success'
            })
            this.getList()
          } else {
            this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    }
  }
}
</script>
<style>

</style>